﻿using AutoMapper;
using MediatR;
using S.RBAC.Api.Application.Command.RoleCommand;
using S.RBAC.Domain;
using S.RBAC.Infrastructure.Interface;

namespace S.RBAC.Api.Application.CommandHandlers.RoleHandler
{
    public class RoleUpdateCommandHandler : IRequestHandler<RoleDeleteCommand, int>
    {
        protected readonly IRoleRepository _role;
        protected readonly IMapper _mapper;

        public RoleUpdateCommandHandler(IRoleRepository role, IMapper mapper)
        {
            _role = role;
            _mapper = mapper;
        }

        public async Task<int> Handle(RoleDeleteCommand request, CancellationToken cancellationToken)
        {
            var info = await _role.GetRoleById(request.RoleId);

            info.IsDel = true;

            await _role.UpdRole(info);

            return 1;
        }
    }
}
